package BookManage.qb;


import BookManage.BookManage;
import BookManage.Servlet.BookManageServlet;
import BookManage.Servlet.Impl.BookManageImplServlet;
import BookManage.dao.BookManageDao;
import BookManage.dao.Impl.BookManageDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/cx")
public class cxServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BookManageDao bookManageDao=new BookManageDaoImpl();
        int tot=bookManageDao.getTotalCount();

        Integer Size=null;
        if(tot%5==0){
            Size=(tot/5);
        }else if(tot%5!=0){
            Size=(tot/5)+1;
        }
        System.out.println(Size);

        String page=request.getParameter("BookNo");
        Integer pageNo=null;
        if(null==page){
            pageNo=1;
        }else{
            pageNo=Integer.parseInt(request.getParameter("BookNo"));
        }
        BookManageServlet bookManageServlet=new BookManageImplServlet();
        List<BookManage> lists=bookManageServlet.list(pageNo,5);
        request.setAttribute("Size",Size);
        request.setAttribute("pageNo",pageNo);
        request.setAttribute("lists",lists);
        request.getRequestDispatcher("/BookManage/Ck.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
